﻿// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>

#include "Jobs/Manager.h"

static  void test_job_1(int* x)
{
	std::cout << "test_job_1 with " << *x << std::endl;
	(*x)++;
}
class Test
{
public:
	static void test(int* x)
	{
		(*x)++;
		printf("class static function\n");
	}
};
struct test_job_2
{
	void Execute(int* x)
	{
		(*x)++;
		std::cout << "test_job_2::Execute with " << *x << std::endl;
	}
};

void main_test(Anger::Manager* manager)
{
	printf("main fiber\n");

	int count = 1;
	test_job_2 tj2_inst;
	manager->WaitForSingle(Anger::JobPriority::Normal, test_job_1, &count);
	manager->WaitForSingle(Anger::JobPriority::Normal, Test::test, &count);
	manager->WaitForSingle(Anger::JobPriority::Normal, [&count]()
	{
			count++;
			printf("xxxxxxxxxxxx\n");
	});

	manager->WaitForSingle(Anger::JobPriority::Normal, &test_job_2::Execute, &tj2_inst, &count);

}
int main()
{
	Anger::Options managerOptions;
	managerOptions.numFiber = 25;
	managerOptions.threadAffinity = true;

	managerOptions.HighPriorQueuSize = 128;
	managerOptions.normalPriorQueuSize = 256;
	managerOptions.lowPriorQueuSize = 256;

	managerOptions.ShutdownAfterMainCallback = true;
	Anger::Manager manager(managerOptions);
	manager.Run(main_test);

	std::cout << "Hello World!\n";
}

